package com.retail.system.service.impl;


import com.retail.system.entity.vo.AdminUpgradeConfigVo;
import com.retail.core.entity.ParamReq;
import com.retail.system.entity.request.AdminUpgradeConfigRequest;
import com.retail.system.mapper.AdminUpgradeConfigMapper;
import com.retail.system.service.AdminUpgradeConfigService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* 团队长晋升配置1 Service impl
* @author Administrator
*/
@Service
public class AdminUpgradeConfigServiceImpl implements AdminUpgradeConfigService {

   @Resource
   private AdminUpgradeConfigMapper adminUpgradeConfigMapper;

   @Cacheable(value = "GET_ADMIN_UPGRADE_CONFIG", key = "#id")
   @Override
   public AdminUpgradeConfigVo getModel(Long id) {
      return  adminUpgradeConfigMapper.getModel(id);
   }
   
   @Transactional
   @Override
   public Long save(AdminUpgradeConfigRequest adminUpgradeConfigRequest) {
      adminUpgradeConfigMapper.save(adminUpgradeConfigRequest);
      return adminUpgradeConfigRequest.getId();
   }

   @CacheEvict(value = "GET_ADMIN_UPGRADE_CONFIG", key = "#request.id")
   @Transactional
   @Override
   public Long update(AdminUpgradeConfigRequest request) {
      adminUpgradeConfigMapper.update(request);
      return request.getId();
   }

   @Cacheable(value = "ADMIN_UPGRADE_CONFIG_LIST", key = "#params.hashCode()")
   @Override
   public List<AdminUpgradeConfigVo> listPage(ParamReq<AdminUpgradeConfigRequest> params) {
      params.setStartIndex((params.getCurrent() -1 ) * params.getSize());
      return adminUpgradeConfigMapper.listPage(params);
   }

   @Cacheable(value = "ADMIN_UPGRADE_CONFIG_COUNT", key = "#params.hashCode()")
   @Override
   public Integer countPage(ParamReq<AdminUpgradeConfigRequest> params) {
       return adminUpgradeConfigMapper.countPage(params);
   }

   @CacheEvict(value = "GET_ADMIN_UPGRADE_CONFIG", key = "#id")
   @Override
   public Integer updateDelFlagById(Long id, Integer delFlag) {
       return adminUpgradeConfigMapper.updateDelFlagById(id, delFlag);
   }
}
